package com.sias.judgeservice.judge.codsandbox.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.sias.judgeservice.judge.codsandbox.CodeSandbox;
import com.sias.model.model.codsandbox.ExecuteCodeRequest;
import com.sias.model.model.codsandbox.ExecuteCodeResponse;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2023/12/10 20:11
 */
public class RemoteCodeSandbox implements CodeSandbox {

  @Override
  public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
    String executeCodeResponse = HttpUtil.post("http://localhost:8090/doJudge", JSONUtil.toJsonStr(executeCodeRequest));
    // String url = "http://localhost:8090/doJudge";
    // String res = HttpUtil.createPost(url).body(JSONUtil.toJsonStr(executeCodeRequest)).execute().body();
    ExecuteCodeResponse codeResponse = JSONUtil.toBean(executeCodeResponse, ExecuteCodeResponse.class);
    return codeResponse;
  }
}
